Micron Document
🎖️GitЯра🎖️


Displaying Raw • Download

feature/map/src/commonMain/kotlin/org/meshtastic/feature/map/layers/MapLayer.kt renovate/fastlane-2.x-lockfile (056eed64) Text, 6.91 KB

T8b949e/*
* Copyright (c) 2026 Meshtastic LLC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
Tff7b72package T7ee787org.meshtastic.feature.map.layers

Tff7b72import T7ee787kotlin.uuid.Uuid

T8b949e/**
* The imported-overlay model, shared by every renderer.
*
* Only the final overlay draw is platform- or flavour-specific; the layer list, its storage and the import plumbing
* live in [MapLayersManager]. This is common code rather than Android's because the desktop app imports layers too — so
* [uri] is a plain string: an Android `content://`, a `file://` under the app's own storage, or an `http(s)` network
* layer, parsed where it is used rather than by a platform URI type here.
*/
Tff7b72enum Tff7b72class T56d364LayerType Tb4b4b4{
Te6edf3KMLTb4b4b4,
Te6edf3GEOJSONTb4b4b4,

T8b949e/**
* A Site Planner coverage estimate. GeoJSON on the wire and parsed as such, but tracked as its own type so the
* layers sheet can distinguish an estimate we generated from a GeoJSON file the user imported.
*/
Te6edf3COVERAGETb4b4b4,
Tb4b4b4}

Tff7b72data Tff7b72class T56d364MapLayerItemTb4b4b4(
Tff7b72val Te6edf3idTb4b4b4: Tffa657String Tff7b72= Te6edf3UuidTb4b4b4.Te6edf3randomTb4b4b4(Tb4b4b4)Tb4b4b4.Te6edf3toStringTb4b4b4(Tb4b4b4)Tb4b4b4,
Tff7b72val Te6edf3nameTb4b4b4: Tffa657StringTb4b4b4,
Tff7b72val Te6edf3uriTb4b4b4: Tffa657String? Tff7b72= Tff7b72nullTb4b4b4,
Tff7b72val Te6edf3isVisibleTb4b4b4: Tffa657Boolean Tff7b72= Tff7b72trueTb4b4b4,
Tff7b72val Te6edf3layerTypeTb4b4b4: Te6edf3LayerTypeTb4b4b4,
Tff7b72val Te6edf3isNetworkTb4b4b4: Tffa657Boolean Tff7b72= Tff7b72falseTb4b4b4,
T8b949e/** Wall-clock creation time, from the backing file's mtime. Null for network layers, which have no local file. */
Tff7b72val Te6edf3createdAtTb4b4b4: Tffa657Long? Tff7b72= Tff7b72nullTb4b4b4,
T8b949e/** UI indicator: whether a refresh is in flight (drives the sheet/toolbar spinner). */
Tff7b72val Te6edf3isRefreshingTb4b4b4: Tffa657Boolean Tff7b72= Tff7b72falseTb4b4b4,
T8b949e/**
* Monotonic counter bumped on refresh so the renderers reliably re-read the layer. A `StateFlow` conflates
* transient values, so a bounced boolean flag can be missed — an ever-increasing token cannot.
*/
Tff7b72val Te6edf3refreshTokenTb4b4b4: Tffa657Int Tff7b72= T79c0ff0Tb4b4b4,
Tb4b4b4)

Tff7b72private Tff7b72val Te6edf3KML_EXTENSIONS Tff7b72= Te6edf3listOfTb4b4b4(Ta5d6ff"Ta5d6ffkmlTa5d6ff"Tb4b4b4, Ta5d6ff"Ta5d6ffkmzTa5d6ff"Tb4b4b4, Ta5d6ff"Ta5d6ffvnd.google-earth.kml+xmlTa5d6ff"Tb4b4b4, Ta5d6ff"Ta5d6ffvnd.google-earth.kmzTa5d6ff"Tb4b4b4)
Tff7b72private Tff7b72val Te6edf3GEOJSON_EXTENSIONS Tff7b72= Te6edf3listOfTb4b4b4(Ta5d6ff"Ta5d6ffgeojsonTa5d6ff"Tb4b4b4, Ta5d6ff"Ta5d6ffjsonTa5d6ff"Tb4b4b4)

T8b949e/** Zip magic bytes; a [LayerType.KML] source starting with these is a KMZ archive rather than bare KML. */
Tff7b72private Tff7b72val Te6edf3KMZ_MAGIC Tff7b72= Te6edf3byteArrayOfTb4b4b4(Ta5d6ff'P'Tb4b4b4.Te6edf3codeTb4b4b4.Te6edf3toByteTb4b4b4(Tb4b4b4)Tb4b4b4, Ta5d6ff'K'Tb4b4b4.Te6edf3codeTb4b4b4.Te6edf3toByteTb4b4b4(Tb4b4b4)Tb4b4b4)

T8b949e/**
* True if [this] starts with the zip magic bytes, meaning a nominally-[LayerType.KML] source (`.kml` and `.kmz` both
* resolve to that one type) is actually a KMZ archive. Sniffed rather than taken from the file extension, which a
* content resolver can get wrong.
*/
Tff7b72fun Te6edf3ByteArrayTb4b4b4.Td2a8ffisKmzArchiveTb4b4b4(Tb4b4b4)Tb4b4b4: Tffa657Boolean Tff7b72= Te6edf3size Tff7b72>Tff7b72= Te6edf3KMZ_MAGICTb4b4b4.Te6edf3size Tff7b72&Tff7b72& Te6edf3KMZ_MAGICTb4b4b4.Te6edf3indicesTb4b4b4.Te6edf3all Tb4b4b4{ Tff7b72thisTff7b72[Tffa657itTff7b72] Tff7b72=Tff7b72= Te6edf3KMZ_MAGICTff7b72[Tffa657itTff7b72] Tb4b4b4}

T8b949e/**
* Ceiling on the bytes one KMZ may inflate to, summed across every entry read from it.
*
* A zip's inflated size is unrelated to its size on disk, and KMZ files arrive through share-into-app — an unbounded
* read hands any other app the ability to OOM this one with a small file. Every KMZ reader shares this cap.
*/
Tff7b72const Tff7b72val Te6edf3MAX_KMZ_INFLATED_BYTESTb4b4b4: Tffa657Long Tff7b72= T79c0ff5T79c0ff0L Tff7b72* T79c0ff1T79c0ff0T79c0ff2T79c0ff4 Tff7b72* T79c0ff1T79c0ff0T79c0ff2T79c0ff4

T8b949e/** On-disk extension marking a saved coverage estimate, so [LayerType.COVERAGE] survives a restart. */
Tff7b72const Tff7b72val Te6edf3COVERAGE_EXTENSION Tff7b72= Ta5d6ff"Ta5d6ffcoverageTa5d6ff"

T8b949e/**
* The extension an imported layer is stored under.
*
* Derived from the resolved type rather than carried over from the import, because the import's own "extension" may be
* a MIME subtype: storing a file as `route.vnd.google-earth.kml+xml` would leave `xml` behind the last dot, which
* resolves to no type at all, and the layer would disappear on the next start. A KMZ stored as `.kml` is fine — the
* readers sniff the zip magic rather than trusting the name.
*/
Tff7b72internal Tff7b72fun Te6edf3LayerTypeTb4b4b4.Td2a8ffstorageExtensionTb4b4b4(Tb4b4b4)Tb4b4b4: Tffa657String Tff7b72= Tff7b72when Tb4b4b4(Tff7b72thisTb4b4b4) Tb4b4b4{
Te6edf3LayerTypeTb4b4b4.Te6edf3KML Tff7b72-Tff7b72> Ta5d6ff"Ta5d6ffkmlTa5d6ff"
Te6edf3LayerTypeTb4b4b4.Te6edf3GEOJSON Tff7b72-Tff7b72> Ta5d6ff"Ta5d6ffgeojsonTa5d6ff"
Te6edf3LayerTypeTb4b4b4.Te6edf3COVERAGE Tff7b72-Tff7b72> Te6edf3COVERAGE_EXTENSION
Tb4b4b4}

T8b949e/**
* Coverage estimates append a random UUID to their on-disk name so two estimates saved under the same title don't
* collide. The layers list rebuilds its display name from that file name, so strip the suffix or the raw UUID shows up
* in the UI.
*/
Tff7b72private Tff7b72val Te6edf3TRAILING_UUID Tff7b72=
Te6edf3RegexTb4b4b4(Ta5d6ff"Ta5d6ff_[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$Ta5d6ff"Tb4b4b4, Te6edf3RegexOptionTb4b4b4.Te6edf3IGNORE_CASETb4b4b4)

T8b949e/** Recover a layer's display name from its on-disk file name (sans extension). */
Tff7b72fun Td2a8ffdisplayNameFromFileNameTb4b4b4(Te6edf3fileNameWithoutExtensionTb4b4b4: Tffa657StringTb4b4b4)Tb4b4b4: Tffa657String Tff7b72=
Te6edf3fileNameWithoutExtensionTb4b4b4.Te6edf3replaceTb4b4b4(Te6edf3TRAILING_UUIDTb4b4b4, Ta5d6ff"Ta5d6ff"Tb4b4b4)

T8b949e/**
* Characters not allowed in an on-disk layer file name: path separators, so an import can't traverse out of the layers
* directory, plus control characters. Everything else — spaces, punctuation, non-Latin scripts — is kept, because the
* list rebuilds a layer's display name from this file name and users should see the name they chose.
*/
Tff7b72private Tff7b72val Te6edf3FILE_NAME_UNSAFE Tff7b72= Te6edf3RegexTb4b4b4(Ta5d6ff"""Ta5d6ff[/Ta5d6ff\\Ta5d6ff\Ta5d6ffp{Cntrl}]Ta5d6ff"""Tb4b4b4)

T8b949e/**
* Longest sanitized base name kept, in characters. Bounds the total path length: the UUID suffix and extension add ~46
* bytes, and a non-Latin name can reach 4 bytes per character, which would otherwise overrun the 255-byte file name
* limit and fail the write.
*/
Tff7b72private Tff7b72const Tff7b72val Te6edf3MAX_BASE_NAME_CHARS Tff7b72= T79c0ff4T79c0ff0

T8b949e/**
* Build the on-disk file name for a layer from its [displayName].
*
* [displayName] is untrusted (a name from another app's share/open-with, or whatever the user called the file), so
* separators are stripped to keep the write inside the layers directory. The UUID suffix is load-bearing, not cosmetic:
* two layers sharing a display name would otherwise resolve to the same path and the second write would truncate the
* first. It also means a name of `..` can never itself be the file name. [displayNameFromFileName] strips it back off
* for display.
*/
Tff7b72fun Td2a8fflayerFileNameTb4b4b4(Te6edf3displayNameTb4b4b4: Tffa657StringTb4b4b4, Te6edf3extensionTb4b4b4: Tffa657StringTb4b4b4)Tb4b4b4: Tffa657String Tb4b4b4{
Tff7b72val Te6edf3safeBase Tff7b72= Te6edf3displayNameTb4b4b4.Te6edf3replaceTb4b4b4(Te6edf3FILE_NAME_UNSAFETb4b4b4, Ta5d6ff"Ta5d6ff_Ta5d6ff"Tb4b4b4)Tb4b4b4.Te6edf3takeTb4b4b4(Te6edf3MAX_BASE_NAME_CHARSTb4b4b4)
Tff7b72return Ta5d6ff"Tffd700${Te6edf3safeBaseTffd700}Ta5d6ff_Tffd700${Te6edf3UuidTb4b4b4.Te6edf3randomTb4b4b4(Tb4b4b4)Tffd700}Ta5d6ff.Tffd700$Te6edf3extensionTa5d6ff"
Tb4b4b4}

T8b949e/**
* Resolve a file extension or MIME subtype (e.g. `geojson`, `vnd.geo+json`) to a [LayerType], or null if unsupported.
*/
Tff7b72fun Td2a8ffresolveLayerTypeTb4b4b4(Te6edf3extensionOrMimeTb4b4b4: Tffa657String?Tb4b4b4)Tb4b4b4: Te6edf3LayerType? Tff7b72= Tff7b72when Tb4b4b4(Te6edf3extensionOrMimeTff7b72?.Te6edf3lowercaseTb4b4b4(Tb4b4b4)Tb4b4b4) Tb4b4b4{
Tff7b72in Te6edf3KML_EXTENSIONS Tff7b72-Tff7b72> Te6edf3LayerTypeTb4b4b4.Te6edf3KML

Tff7b72in Te6edf3GEOJSON_EXTENSIONS Tff7b72-Tff7b72> Te6edf3LayerTypeTb4b4b4.Te6edf3GEOJSON

Te6edf3COVERAGE_EXTENSION Tff7b72-Tff7b72> Te6edf3LayerTypeTb4b4b4.Te6edf3COVERAGE

T8b949e// MIME subtypes the content resolver may report for GeoJSON that aren't a bare "geojson"/"json".
Ta5d6ff"Ta5d6ffgeo+jsonTa5d6ff"Tb4b4b4,
Ta5d6ff"Ta5d6ffvnd.geo+jsonTa5d6ff"Tb4b4b4,
Tff7b72-Tff7b72> Te6edf3LayerTypeTb4b4b4.Te6edf3GEOJSON

Tff7b72else Tff7b72-Tff7b72> Tff7b72null
Tb4b4b4}

Served by rngit 1.5.2 - Generated in 0.12s